package com.sdtv.basemodule.mvp.presenter;

import androidx.appcompat.app.AppCompatActivity;

import com.sdtv.basemodule.mvp.IModel;
import com.sdtv.basemodule.mvp.IView;
import com.sdtv.basemodule.rx.RxBusObserver;

/**
 * @ProjectName: MediunFusion
 * @Package: com.sdtv.basemodule.mvp
 * @ClassName: BasePresenter
 * @Description: --MVP basePresneter
 * @Author: 小郭同学
 * @CreateDate: 2019-06-19 15:18
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public abstract class BasePresenter<V extends IView, M extends IModel> extends IPresenter {


    protected V mView;

    protected M mModel;


    @Override
    public void attachView(AppCompatActivity activity, IView view) {
        super.attachView(activity, view);
        this.mView = (V) view;
        mModel = (M) new IModel(mView);
        initRepository();
    }

    /**
     * 初始化数据仓库
     */
    public abstract void initRepository();

    /**
     * 移除控件
     */
    @Override
    public void detachView() {
        this.mView = null;
    }

    /**
     * 是否已经移除了view
     *
     * @return
     */
    @Override
    public boolean isAttachView() {
        return null != this.mView;
    }

    @Override
    public void subscribeEvent(Class<?> eventType, RxBusObserver subscriber) {
        super.subscribeEvent(eventType, subscriber);
    }
}
